import * as types from './bankMutationTypes';
import arrayUtil from '../../../common/arrayUtil';
// import assignDeep from 'assign-deep';

/**
 * mutations
 * @type {{}}
 */
const mutations = {

  [types.SYS_FILE_UPLOAD_QUERY_TOKEN](state) {
  },
  [types.SYS_FILE_UPLOAD_SAVE_FILE_BEGIN](state) {
  },
  [types.SYS_FILE_UPLOAD_SAVE_FILE_SUC](state, {newdata}) {

    let banks = state.banks || [];
    banks.push(newdata);
    state.banks = banks;
  },
  [types.SYS_FILE_UPLOAD_UPDATE_SUC](state, {formData}) {

    let file = state.banks.find((item) => {
      return item.id === formData.id;
    });
    file.singleLimit = formData.singleLimit;
    file.dayLimit = formData.dayLimit;
    file.monthLimit = formData.monthLimit;
    file.state = formData.state;
    file.bankName = formData.bankName;
    file.bankCode = formData.bankCode;
    file.channel = formData.channel;
  },

  [types.SYS_FILE_UPLOAD_DELETE_SUC](state, {id}) {
    console.log(state.banks)
    console.log(id)
    arrayUtil.removeItem(state.banks, 'id', id);
  },

  [types.SYS_FILE_UPLOAD_QUERY_FILES_BEGIN](state) {
    state.banks = [];
  },

  [types.SYS_FILE_UPLOAD_QUERY_FILES_SUC](state, {banks}) {
    state.banks = banks || [];
  }

};

export default mutations;
